package com.glsc.ngateway.common.base.domain.mysql.cmdb;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;

@Data
@Entity
@Table(name = "t_cmdb_cpu_detail")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CmdbCpuDetail {
    @Column(name = "assert_num", length = 100)
    private String assertNum;

    @Column(name = "assert_id", length = 100)
    private String assertId;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @Column(name = "purchase_date", columnDefinition = "date DEFAULT NULL COMMENT '购置日期'")
    private LocalDate purchaseDate;
    @Column(name = "input_price_with_tax", columnDefinition = "decimal(15,4) COMMENT '入库金额（含税）'")
    private BigDecimal inputPriceWithTax;

    @Column(name = "input_price_no_tax", columnDefinition = "decimal(15,4) COMMENT '不含税金额'")
    private BigDecimal inputPriceNoTax;

    @Column(name = "user")
    private String user;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "cpu_detal_id", columnDefinition = "bigint")
    private Integer cpuDetailId;

    @Column(name = "cpu_detail_code", length = 100, columnDefinition = "varchar(100) DEFAULT NULL COMMENT 'cpu明细业务编码'")
    private String cpuDetailCode;

    @Column(name = "cpu_standard_code", length = 100, columnDefinition = "varchar(100) DEFAULT NULL COMMENT 'cpu规格业务编码'")
    private String cpuStandardCode;

    @ManyToOne
    @JoinColumn(name = "cpu_standard_code",referencedColumnName = "cpu_standard_code",foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT), insertable = false, updatable = false)
    private CmdbCpuStandard cmdbCpuStandard;

    @Transient
    private String partNum;

    @Column(name = "sn", length = 100, columnDefinition = "varchar(100) DEFAULT NULL COMMENT '序列号'")
    private String sn;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @Column(name = "manufact_date", columnDefinition = "date DEFAULT NULL COMMENT '生产日期'")
    private LocalDate manufactDate;

    @Column(name = "device_code", columnDefinition = "varchar(100) DEFAULT NULL COMMENT '设备明细code'")
    private String deviceCode;

    @Column(name = "life_status", columnDefinition = "tinyint DEFAULT 0 COMMENT 'PART_LIFE_CYCLE生命周期  库存，已分配，已报废，分配待确认'")
    private Integer lifeStatus;

    @Column(name = "location_id", columnDefinition = "int DEFAULT NULL COMMENT '位置id  库存状态是机房id\\r\\n装机状态是服务器明细id'")
    private Integer locationId;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @Column(name = "expirate_date", columnDefinition = "date DEFAULT NULL COMMENT '过保日期'")
    private LocalDate expirateDate;

    @Column(name = "is_delete", nullable = true, columnDefinition = "int DEFAULT '0' COMMENT '是否删除，0未删除，1 已删除'")
    private Integer isDelete;

    // Getters and Setters

}
